package com.intelligence.tio.server.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.Aio;
import org.tio.core.ChannelContext;
import org.tio.json.Json;

import com.intelligence.tio.common.Command;
import com.intelligence.tio.common.JsonPacket;
import com.intelligence.tio.common.TioSessionContext;
import com.intelligence.tio.common.intf.AbsTioBsHandler;
import com.intelligence.tio.common.packages.DataErrorRespBody;
import com.intelligence.tio.common.packages.P2PReqBody;
import com.intelligence.tio.common.packages.P2PRespBody;

/**
* @Title: DataErrorReqHandler.java 
* @Package com.intelligence.tio.server.handler 
* @Description: TODO(用一句话描述该文件做什么) 
* @Company: 消息格式错误处理器
* @author 郭浩柱  
* @date 2017年5月22日 下午4:33:21 
* @version V1.0
 */
public class DataErrorReqHandler extends AbsTioBsHandler<DataErrorRespBody>
{
	private static Logger log = LoggerFactory.getLogger(DataErrorReqHandler.class);

	/** 
	 * 
	 */
	@Override
	public Class<DataErrorRespBody> bodyClass()
	{
		return DataErrorRespBody.class;
	}

	@Override
	public Object handler(JsonPacket packet, DataErrorRespBody bsBody, ChannelContext<TioSessionContext, JsonPacket, Object> channelContext) throws Exception
	{
		log.info("收到数据格式错误请求消息:{}", Json.toJson(bsBody));
		
		//提示发送用户数据格式发送错误
		DataErrorRespBody body = new DataErrorRespBody();
		body.setCommand(Command.COMMAND_DATA_ERROR_RESP.getValue());
		body.setCode(-1);
		body.setMsg("数据格式错误，请发送正确JSON格式数据！");
		JsonPacket respPacket = new JsonPacket();
		respPacket.setBody(Json.toJson(body).getBytes(JsonPacket.CHARSET));
		Aio.send(channelContext, respPacket);
		return null;
	}
}
